package simonxianyu.demo.shiro.config;

import org.springframework.web.filter.DelegatingFilterProxy;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.DispatcherType;
import javax.servlet.FilterRegistration;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import java.util.EnumSet;

/**
 *
 * Created by simon on 2017/3/4.
 */
public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
  @Override
  public void onStartup(ServletContext servletContext) throws ServletException {
    FilterRegistration.Dynamic filterRegistration = servletContext.addFilter("shiro", new DelegatingFilterProxy("shiroFilter"));
    filterRegistration.setInitParameter("targetFilterLifecycle","true");
    filterRegistration.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");
    super.onStartup(servletContext);
  }

  @Override
  protected Class<?>[] getRootConfigClasses() {
    return new Class<?>[]{RootContext.class, ShiroConfig.class};
  }

  @Override
  protected Class<?>[] getServletConfigClasses() {
    return new Class<?>[]{WebContext.class};
  }

  @Override
  protected String[] getServletMappings() {
    return new String[]{"/"};
  }
}
